import 'package:flutter/material.dart';

class ChipDemo extends StatefulWidget {
  @override
  _ChipDemoState createState() => _ChipDemoState();
}

class _ChipDemoState extends State<ChipDemo> {
  double _sliderItemA = 0;
  List<String> _tags = ['ads', 'fdsa', 'fffdfs'];
  String _action = 'fdsa';
  List<String> _selected = [];
  String _choice = 'fffdfs';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ChipDemo1'),
        elevation: 0,
      ),
      body: Container(
        padding: EdgeInsets.all(16),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Wrap(
              spacing: 30,
              runSpacing: 10,
              children: [
                Text('aa'),
                Chip(
                  label: Text("life"),
                ),
                Chip(
                  label: Text("life"),
                  backgroundColor: Colors.red,
                ),
                Chip(
                  label: Text("life"),
                  avatar: CircleAvatar(
                    backgroundColor: Colors.grey,
                    child: Text('AA'),
                  ),
                ),
                Chip(
                  label: Text("life"),
                  avatar: CircleAvatar(
                    backgroundImage: NetworkImage(
                        'https://resources.ninghao.net/images/wanghao.jpg'),
                    child: Text('AA'),
                  ),
                ),
                Divider(
                  color: Colors.red,
                  height: 10,
                ),
                Chip(
                  label: Text("life"),
                  onDeleted: () {},
                  deleteIcon: Icon(Icons.delete),
                  deleteIconColor: Colors.blue,
                  deleteButtonTooltipMessage: 'fdsafdsa',
                ),
                Wrap(
                  spacing: 10,
                  children: _tags.map((tag) {
                    return Chip(
                      label: Text(tag),
                      onDeleted: () {
                        setState(() {
                          _tags.remove(tag);
                        });
                      },
                    );
                  }).toList(),
                ),
                Container(
                  width: double.infinity,
                  child: Text(_action),
                ),
                Wrap(
                  spacing: 10,
                  children: _tags.map((tag) {
                    return ActionChip(
                      label: Text(tag),

                      onPressed: () {
                        setState(() {
                          _action = tag;
                        });
                      },
                    );
                  }).toList(),
                ),
                Container(
                  width: double.infinity,
                  child: Text('filterChip:${_selected.toString()}'),
                ),
                Wrap(
                  spacing: 10,
                  children: _tags.map((tag) {
                    return FilterChip(
                      label: Text(tag),
                      selected: _selected.contains(tag),
                      onSelected: (value) {
                        setState(() {
                          if (_selected.contains(tag)) {
                            _selected.remove(tag);
                          } else {
                            _selected.add(tag);
                          }
                        });
                      },
                    );
                  }).toList(),
                ),
                Container(
                  width: double.infinity,
                  child: Text('choice:${_choice}'),
                ),
                Wrap(
                  spacing: 10,
                  children: _tags.map((tag) {
                    return ChoiceChip(
                      label: Text(tag),
                      selectedColor: Colors.black87,
                      labelStyle:TextStyle( color: Colors.red, ) ,
                      selected: _choice==tag,
                      onSelected: (value) {
                        setState(() {
                          _choice=tag;
                        });
                      },
                    );
                  }).toList(),
                ),
              ],
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.restore),
        onPressed: () {
          setState(() {
            _tags = ['ads', 'fdsa', 'fffdfs'];
            _selected=[];
              _choice = 'fffdfs';

          });
        },
      ),
    );
  }
}
